package com.csg.ses.common.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executors;

/**
 * @auther wangjun
 * @time 2020/12/14 12:51
 * 设置Schedule为多线程执行定时任务
 * Schedule默认是单线程运行定时任务的，即使是多个不同的定时任务，默认也是单线程运行。当线程挂掉时，定时任务也随之终止
 */
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        //设定一个长度10的定时任务线程池
        taskRegistrar.setScheduler(Executors.newScheduledThreadPool(10));
    }
}
